package com.wenhao.binalifeng;

import javax.imageio.stream.FileCacheImageOutputStream;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-09-01 17:29
 */
public class Main3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String w = scanner.nextLine();
        String[] split = w.split(",");
        int[] weights = new int[split.length];
        for (int i = 0;i < weights.length;i++) {
            weights[i] = Integer.parseInt(split[i]);
        }
        int capacity = scanner.nextInt();
        int[][] dp = new int[weights.length + 1][capacity + 1];
        for (int i = 1;i < dp.length;i++) {
            for (int j = 1;j < dp[i].length;j++) {
                if (j >= weights[i - 1]) {
                    dp[i][j] = Math.max(dp[i - 1][j],dp[i - 1][j - weights[i - 1]] + 1);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[weights.length][capacity]);
    }
}
